<?php
@session_start();
require(dirname(__FILE__) . '/../includes/global.php');
require(dirname(__FILE__) . '/../includes/article.libs.php');

$action   = $_REQUEST['action'];
//if(!empty($_POST)) {
    $conn   = & get_db_conn();
    if($action=='chknumber'){
        $chknumber=$_REQUEST['chknumber'];
        if($_SESSION['randcode']!=$chknumber){
            echo 1;
        }echo 0;exit;
    }elseif($action=='image_upload'){
       global $mod, $G_abs_includes;
        require($G_abs_includes . '/upload.php');
        $up = upload_files($mod,$makethumbwidth,$makethumbheight); print_r($up);
        exit;
    }elseif($action=='getCity'){
        $num=@(int)$_REQUEST['num'];
        $id=@(int)$_REQUEST['cid'];
        $noid=@(int)$_REQUEST['noid'];
        $type=@(int)$_REQUEST['type'];
        if($num==1){
            $wh=" where num=$id and num1=0";
        }else{
			$g = $conn->GetOne("SELECT `num` FROM ".$_TABLES['city']." WHERE id='$id' ");
            $wh=" where num=$g and num1=$id";
        }
        if($noid){
            $wh.=" and id<>$noid ";
        }
        $data=$conn->GetAll("SELECT id,cname FROM ".$_TABLES['city']." $wh");
        echo json_encode(array('type'=>1,'data'=>$data));
        exit;
    }elseif($action=='goodsc'){
        $uid=@(int)$_REQUEST['uid'];
        $gid=@(int)$_REQUEST['gid'];
        $u = $conn->GetOne("SELECT `uid` FROM ".$_TABLES['members']." WHERE uid='$uid' ");
        if($u){
            $g = $conn->GetOne("SELECT `id` FROM ".$_TABLES['collect']." WHERE uid='$uid' and gid='$gid' ");
            if($g){
                echo json_encode(array('type'=>1,'data'=>'您已收藏过该产品'));
                exit;
            }else{
                if($conn->AutoExecute($_TABLES['collect'],array('uid'=>$uid,'gid'=>$gid,'add_time'=>time()),'INSERT')) {
                    echo json_encode(array('type'=>1,'data'=>'收藏成功'));
                    exit;   
                }else{
                    echo json_encode(array('type'=>0,'data'=>'收藏失败，请重试'));
                    exit;
                }
            }
        }else{
            echo json_encode(array('type'=>1,'data'=>'请先登录账户'));
            exit;
        }
    }elseif($action=='lkview'){
        /*$uid=@(int)$_REQUEST['uid'];
        $aid=@(int)$_REQUEST['aid'];
        $serid=@(int)$_REQUEST['serid'];
        $viewid=@(int)$_REQUEST['viewid'];
        $tao=$conn->GetRow("SELECT taocan FROM $tbl_article WHERE aid='{$aid}' and display=1 ");
        if(($serid && $viewid)||$tao['taocan']==2||$tao['taocan']==3){
            $data=$conn->GetRow("SELECT lkTime,lkSex,lkMan,lkPhone FROM $tbl_article WHERE aid='{$aid}' and display=1 ");
            if($data['lkSex']){
                $data['lkSex']='女';
            }else{
                $data['lkSex']='男';
            }
            echo json_encode(array('type'=>0,'data'=>$data));
        }
        $u = $conn->GetOne("SELECT `uid` FROM ".$_TABLES['members']." WHERE uid='$uid' ");
        if($u){
            $tbl_members_ser        = $_TABLES['members_ser'];
            $tbl_view_log        = $_TABLES['view_log'];
            $tbl_article        = $_TABLES['article'];
            $ser=$conn->GetRow("SELECT id,ser_num FROM $tbl_members_ser WHERE uid='{$u['uid']}' and end_time>".time()." and ser_num>0");
            if($ser['id']){
                if($conn->AutoExecute($tbl_members_ser,array('ser_num'=>(@(int)$ser['ser_num']-1)),'UPDATE', 'id=' . $ser['id'])){
                    $conn->AutoExecute($tbl_view_log,array('uid'=>$uid,'aid'=>$aid,'add_time'=>time()),'INSERT');
                    $data=$conn->GetRow("SELECT lkTime,lkSex,lkMan,lkPhone FROM $tbl_article WHERE aid='{$aid}' and display=1 ");
                    if($data['lkSex']){
                        $data['lkSex']='女';
                    }else{
                        $data['lkSex']='男';
                    }
                    echo json_encode(array('type'=>0,'data'=>$data));
                }else{
                    echo json_encode(array('type'=>1,'data'=>'请重试！'));
                }
            }else{
                if($viewid)
                    echo json_encode(array('type'=>1,'data'=>'您的次数已用完，或已过期，请重新申请！'));
                else
                    echo json_encode(array('type'=>1,'data'=>'请先申请服务！'));
            }
        }else{
            echo json_encode(array('type'=>1,'data'=>'请先登录账户'));
        }
        exit;*/
    }elseif($action=="sendCaptcha"){ //发送手机验证码
        $info = $_REQUEST['info'];
        $lost = $_REQUEST['lost'];
        $phone = $info;
        $pwd = random(6, 1);
        $time = 10;
        $result = 0;
        if(!$lost){
            $id = $conn->GetOne("SELECT uid FROM ".$_TABLES['members']." WHERE tel = '$phone'");
            if(!$id){
                ssetcookie('phone_captcha', $pwd, $time*60+time());
                ssetcookie('phone_captchaNum', $phone, $time*60+time());

                $result=sms_send_lor($phone,"尊敬的客户你好，你的验证码是{$pwd}，验证码在{$time}分钟内有效!");
            }else{
                $result = 999;//手机号已被占用
            }
        }else{
            $lost = $_REQUEST['lost'];
            $id = $conn->GetOne("SELECT uid FROM ".$_TABLES['members']." WHERE tel = '$phone'");
            if(!$id){
                $result = 999;//手机号不存在
            }else{
                $result=sms_send_lor($phone,"尊敬的客户你好，{$G_cfg[site_info][sms_sitename]}已将你的密码已重置为{$pwd}!【{$G_cfg[site_info][sms_sitename]}】");
                if($result>0){
                    $conn->AutoExecute($_TABLES['members'],array('password'=>md5($pwd)),'UPDATE', 'tel=' . $phone );
                }
            }
        }
        echo $result;
        exit;
    }
//}
?>